#include <iostream>
#include <cmath>
using namespace std;

void findMax(int & maxm, int & maxn, int (&space)[21][21], int m, int n){
	int max=-1;
	for(int i = 1; i <= m; i++)
		for(int j = 1; j <= n; j++)
			if(space[i][j] > max){
				maxm = i;
				maxn = j;
				max = space[i][j];
			}
}

int calTime(int nowM, int nowN, int terM, int terN){
	if(nowM == -1 || nowN == -1)
		return terM;
	if(terM == -1 || terN == -1)
		return nowM;
	return abs(terM - nowM) + abs(terN - nowN);
}

int main(){
	int m, n, k;
	cin >> m >> n >> k;
	int space[21][21];
	for(int i = 1; i <= m; i++)
		for(int j = 1; j <= n; j++)
			cin >> space[i][j];
	int maxm = -1;
	int maxn = -1;
	int nowM = -1;
	int nowN = -1;
	int sum = 0;
	while(1){
		findMax(maxm, maxn, space, m, n);
		int temp = space[maxm][maxn];
		int firstTime = calTime(nowM, nowN, maxm, maxn);
		space[maxm][maxn] = 0;
		int secondTime = calTime(maxm, maxn, -1, -1);
		if(firstTime + secondTime + 1 <= k){
			sum += temp;
			nowM = maxm;
			nowN = maxn;
			k = k - firstTime - 1;
		} else {
			cout << sum << endl;
			return 0;
		}
	}
}


